﻿using System.Collections.Generic;
using System.ComponentModel;
using System.ServiceModel.DomainServices.Hosting;
using System.ServiceModel.DomainServices.Server;
using Arch.Aspects;
using Arch.Common.IoC;
using Arch.DomainServices;
using Arch.Samples.Data.Contracts;
using Arch.Samples.Model;
using Microsoft.Practices.ServiceLocation;
using Microsoft.Practices.Unity;

namespace Arch.Samples.RiaServices.Services
{
    [EnableClientAccess]
    [EntityDomainServiceDescriptionProvider(typeof(Todo))]
    [RiaMetadataProviderAttribute]
    //[DomainSecurityAccess(typeof(GlobalCategory), ReadAccess = Access.Authentified, WriteRoles = "Admin")]
    public partial class TodoService : RepositoryDomainService
    {
        [Dependency]
        public ITodoRepository TodoRepository { get; set; }

        public TodoService()
        {   
            //TODO : use DI
            ServiceLocator.Current.BuildUp(this);   
        }

        [Query]
        public IEnumerable<Todo> SearchTodos(string query)
        {
            return TodoRepository.Search(query);
        }
    }
}